#include <stdio.h>
int main() {
    int n = 0, mark1 = 0, mark2 = 0, mark3 = 0, mark4 = 0;
    char a[11][11], b[11][11];
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            scanf(" %c", &b[i][j]);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (b[i][j] != a[n + 1 - j][i])
            {
                mark1++;
            }
            if (b[i][j] != a[j][n + 1 - i])
            {
                mark2++;
            }
            if (b[i][j] != a[n + 1 - i][n + 1 - j])
            {
                mark3++;
            }
            if (a[i][j] != b[i][j])
            {
                mark4++;
            }
        }
    }
    if (mark1 == 0)
    {
        printf("1");
    }
    else if (mark2 == 0)
    {
        printf("2");
    }
    else if (mark3 == 0) 
    {
        printf("3");
    }
    else if (mark4 == 0) 
    {
        printf("4");
    }
    else 
    {
        printf("5");
    }
    return 0;
}